package com.woniuxy.service.impl;

import com.woniuxy.dao.MessageDao;
import com.woniuxy.entity.Message;
import com.woniuxy.utils.TimeUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Data
@Service
public class TestTransaction {
    @Autowired
    private MessageDao messageDao;

    @Transactional(rollbackForClassName={"RuntimeException","Exception"})
    public int addMessage(Message message){
        message.setSendTime(TimeUtils.getNowTime()).setContent("这算是一条消息").setPurpose("纯测试消息")
                .setSender(1).setTarget(100001);
        messageDao.addNewMessage(message);
        System.out.println("----------------------------错误的在下面-------------------------");
        return 1;
//        return messageDao.getCountOfMessage(message.getSender()/0);
    }
}
